package cc.rengu.redp.system.controller;

import cc.rengu.redp.common.domain.RedisInfo;
import cc.rengu.redp.common.domain.RedpResponse;
import cc.rengu.redp.common.redis.RedisInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("redis")
public class RedisController {

    @Autowired
    private RedisInfoService redisInfoService;

    @GetMapping("info")
    public RedpResponse getRedisInfo() throws Exception {
        Map<String, Object> redisInfo = this.redisInfoService.getRedisInfo();
        return new RedpResponse().data(redisInfo);
    }

    @GetMapping("keysSize")
    public Map<String, Object> getKeysSize() throws Exception {
        return redisInfoService.getKeysSize();
    }

    @GetMapping("memoryInfo")
    public Map<String, Object> getMemoryInfo() throws Exception {
        return redisInfoService.getMemoryInfo();
    }

    @GetMapping("clusterNodeInfo")
    public RedpResponse getClusterNodeInfo(String nodeId,String host,int port) throws Exception {
        List<RedisInfo> redisInfo = this.redisInfoService.getClusterNodeInfo(nodeId,host,port);
        return new RedpResponse().data(redisInfo);
    }

    @GetMapping("keysSizeClusterNode")
    public Map<String, Object> getKeysSizeClusterNode(String nodeId,String host,int port) throws Exception {
        return redisInfoService.getKeysSizeClusterNode(nodeId,host,port);
    }

    @GetMapping("memoryInfoClusterNode")
    public Map<String, Object> getMemoryInfoClusterNode(String nodeId,String host,int port) throws Exception {
        return redisInfoService.getMemoryInfoClusterNode(nodeId,host,port);
    }
}
